﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;

namespace MVCFoto.Web.ActionResults
{
    public class RedirectToPromptResult : ActionResult
    {
        private string returnUrl = "";
        private string messages = "";
        private bool redirect = false;
        public RedirectToPromptResult(string messages, string returnUrl, bool redirect)
        {
            this.returnUrl = returnUrl;
            this.messages = messages;
            this.redirect = redirect;           
        }
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            context.Controller.TempData["messages"] = this.messages;
            context.Controller.TempData["url"] = this.returnUrl;
            UrlHelper url = new UrlHelper(context.RequestContext);
            string destinationUrl =  url.RouteUrl("Prompt", new { redirect = this.redirect });
            context.HttpContext.Response.Redirect(destinationUrl, false);
        }
    }
}
